package com.lyf.scm.plan.domain.repository;

import com.lyf.scm.plan.api.dto.DemandPlanDTO;
import com.lyf.scm.plan.api.dto.SalesPlanDirectlyConditionDTO;
import com.lyf.scm.plan.api.dto.SalesPlanDirectlyDTO;
import com.lyf.scm.plan.domain.convertor.SalesPlanDirectlyConvertor;
import com.lyf.scm.plan.domain.convertor.SalesPlanSelectConvertor;
import com.lyf.scm.plan.insfrastructure.db.dataobject.SalesPlanSelectDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyInDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyUpDO;
import com.lyf.scm.plan.insfrastructure.db.mapper.SalesPlanDirectlyMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * description:
 * 直营预测计划
 *
 * @author: haodong
 * @data: 2020/8/3 10:27
 */
@Service
public class SalesPlanDirectlyRepository {

    @Resource
    private SalesPlanDirectlyConvertor salesPlanDirectlyConvertor;

    @Resource
    private SalesPlanSelectConvertor salesPlanSelectConvertor;

    @Resource
    private SalesPlanDirectlyMapper salesPlanDirectlyMapper;


    /**
     * 条件分页查询
     *
     * @param salesPlanDirectly
     * @return
     */
    public List<SalesPlanDirectlyDTO> listByPage(SalesPlanDirectlyDTO salesPlanDirectly) {
        return salesPlanDirectlyConvertor.doToDTO(salesPlanDirectlyMapper.listByPage(salesPlanSelectConvertor.dtoToDO(salesPlanDirectly)));
    }

    /**
     * 条件查询直营预测计划
     *
     * @param salesPlanDirectly
     * @return
     */
    public List<SalesPlanDirectlyDTO> listByConditions(SalesPlanDirectlyDTO salesPlanDirectly) {
        return salesPlanDirectlyConvertor.doToDTO(salesPlanDirectlyMapper.listByConditions(salesPlanDirectlyConvertor.dtoToDO(salesPlanDirectly)));
    }

    /**
     * 查询全部直营预测计划
     *
     * @param salesPlanDirectly
     * @param pageSize
     * @param pageNum
     * @return
     */
    public List<SalesPlanDirectlyDTO> listAllByCycles(SalesPlanDirectlyDTO salesPlanDirectly, Integer pageNum, Integer pageSize) {
        return salesPlanDirectlyConvertor.doToDTO(salesPlanDirectlyMapper.listByCycles(salesPlanSelectConvertor.dtoToDO(salesPlanDirectly),pageNum,pageSize));
    }


    /**
     * 根据id集合查询
     *
     * @param idList
     * @return
     */
    public List<SalesPlanDirectlyDTO> listByIdList(List<Long> idList) {
        return salesPlanDirectlyConvertor.doToDTO(salesPlanDirectlyMapper.listByIdList(idList));
    }

    /**
     * 根据品类 区域 时间条件删选有效信息
     *
     * @param salesPlanSelectDO
     * @return {@link List<SalesPlanDirectlyDTO>}
     **/
    public List<SalesPlanDirectlyConditionDTO> listByCondition(SalesPlanSelectDO salesPlanSelectDO) {
        return salesPlanDirectlyMapper.listByPlanConditions(salesPlanSelectDO);
    }

    public List<SalesPlanDirectlyDTO> listForestPlanQty(DemandPlanDTO demandPlan) {
        return salesPlanDirectlyConvertor.doToDTO(salesPlanDirectlyMapper.listForestPlanQty(demandPlan));
    }

    /**
     * test 大数据取数据接口（门店+日期）
     *
     * @param code
     * @param startDate
     * @param endDate
     * @return {@link List<DirectlyUpDO>}
     **/
    public List<DirectlyUpDO> listAllByStoreAndDate(String code, Date startDate, Date endDate) {
        return salesPlanDirectlyMapper.listAllByStoreAndDate(code, startDate, endDate);
    }
    /**
     * 大数据取数据接口（门店+日期）
     *
     * @param code
     * @param startDate
     * @param endDate
     * @return {@link List<DirectlyUpDO>}
     **/
    public List<DirectlyInDO> listInByStoreAndDate(String code, Date startDate, Date endDate) {
        return salesPlanDirectlyMapper.listInByStoreAndDate(code, startDate, endDate);
    }
    /**
     * 大数据取数据接口（门店+日期）
     *
     * @param code
     * @param startDate
     * @param endDate
     * @return {@link List<DirectlyUpDO>}
     **/
    public List<DirectlyUpDO> listUpByStoreAndDate(String code, Date startDate, Date endDate) {
        return salesPlanDirectlyMapper.listUpByStoreAndDate(code, startDate, endDate);
    }
    /**
     * 大数据批量新增
     *
     * @param directlyInDOs
     * @return void
     **/
    public void batchInsert(List<DirectlyInDO> directlyInDOs) {
        salesPlanDirectlyMapper.batchInsert(directlyInDOs);
    }

    /**
     * 大数据批量更新
     *
     * @param updateList
     * @return void
     **/
    public void batchUpdate(List<SalesPlanDirectlyDTO> updateList) {
        salesPlanDirectlyMapper.batchUpdate(salesPlanDirectlyConvertor.dtoToDO(updateList));
    }


    public void batchDeleteByStartDate(String storeCode, Date weekStartDate) {
        salesPlanDirectlyMapper.batchDeleteByStartDate(storeCode,weekStartDate);
    }

    public List<Long> getIdsByOpSign(String opSign){
        return salesPlanDirectlyMapper.getIdsByOpSign(opSign);
    }


    public void delete(String opSign){
        salesPlanDirectlyMapper.delete(opSign);
    }

    public void rmByIds(List<Long> ids) {
        salesPlanDirectlyMapper.rmByIds(ids);
    }

    public void upByIds(List<DirectlyUpDO> list) {
        salesPlanDirectlyMapper.upByIds(list);
    }

    public void deleteByOpSign(String opSign) {
        salesPlanDirectlyMapper.deleteByOpSign(opSign);
    }


    public List<String> getSkuList(SalesPlanDirectlyDTO directly) {
        return salesPlanDirectlyMapper.getSkuList(salesPlanSelectConvertor.dtoToDO(directly));
    }
}
